package com.upb.webserver.dao.mapper;

import com.upb.webserver.dao.entity.TbApplicationOrg;
import com.upb.webserver.dao.entity.TbApplicationOrgExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.List;
import java.util.Optional;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;

public interface TbApplicationOrgMapper {

    @Delete({ "delete from tb_application_org", "where chain_id = #{chainId,jdbcType=INTEGER}" })
    int deleteByChainId(@Param("chainId") Integer chainId);

    @Select({ "<script>", "select", TbApplicationOrgSqlProvider.ALL_COLUMN_FIELDS, "from tb_application_org", "where org_id in", "<foreach collection='orgIdList' item='orgId' open='(' separator=',' close=')'>", "#{orgId}", "</foreach>", "</script>" })
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "chain_id", property = "chainId", jdbcType = JdbcType.INTEGER), @Result(column = "application_id", property = "applicationId", jdbcType = JdbcType.INTEGER), @Result(column = "org_id", property = "orgId", jdbcType = JdbcType.INTEGER), @Result(column = "chain_type", property = "chainType", jdbcType = JdbcType.TINYINT), @Result(column = "org_type", property = "orgType", jdbcType = JdbcType.TINYINT), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP) })
    List<TbApplicationOrg> selectByOrgIdList(@Param("orgIdList") List<Integer> orgIdList);

    @Select({ "select", TbApplicationOrgSqlProvider.ALL_COLUMN_FIELDS, "from tb_application_org", "where application_id = #{appId,jdbcType=INTEGER} and  org_id = #{orgId,jdbcType=INTEGER}" })
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "chain_id", property = "chainId", jdbcType = JdbcType.INTEGER), @Result(column = "application_id", property = "applicationId", jdbcType = JdbcType.INTEGER), @Result(column = "org_id", property = "orgId", jdbcType = JdbcType.INTEGER), @Result(column = "chain_type", property = "chainType", jdbcType = JdbcType.TINYINT), @Result(column = "org_type", property = "orgType", jdbcType = JdbcType.TINYINT), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP) })
    List<TbApplicationOrg> selectByApplicationAndOrg(@Param("appId") Integer appId, @Param("orgId") Integer orgId);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_application_org
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbApplicationOrgSqlProvider.class, method = "countByExample")
    long countByExample(TbApplicationOrgExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_application_org
     *
     * @mbg.generated
     */
    @DeleteProvider(type = TbApplicationOrgSqlProvider.class, method = "deleteByExample")
    int deleteByExample(TbApplicationOrgExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_application_org
     *
     * @mbg.generated
     */
    @Delete({ "delete from tb_application_org", "where id = #{id,jdbcType=INTEGER}" })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_application_org
     *
     * @mbg.generated
     */
    @Insert({ "insert into tb_application_org (chain_id, application_id, ", "org_id, chain_type, ", "org_type, gmt_create, ", "gmt_modified)", "values (#{chainId,jdbcType=INTEGER}, #{applicationId,jdbcType=INTEGER}, ", "#{orgId,jdbcType=INTEGER}, #{chainType,jdbcType=TINYINT}, ", "#{orgType,jdbcType=TINYINT}, #{gmtCreate,jdbcType=TIMESTAMP}, ", "#{gmtModified,jdbcType=TIMESTAMP})" })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insert(TbApplicationOrg record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_application_org
     *
     * @mbg.generated
     */
    @InsertProvider(type = TbApplicationOrgSqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Integer.class)
    int insertSelective(TbApplicationOrg record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_application_org
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbApplicationOrgSqlProvider.class, method = "selectByExample")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "chain_id", property = "chainId", jdbcType = JdbcType.INTEGER), @Result(column = "application_id", property = "applicationId", jdbcType = JdbcType.INTEGER), @Result(column = "org_id", property = "orgId", jdbcType = JdbcType.INTEGER), @Result(column = "chain_type", property = "chainType", jdbcType = JdbcType.TINYINT), @Result(column = "org_type", property = "orgType", jdbcType = JdbcType.TINYINT), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP) })
    List<TbApplicationOrg> selectByExample(TbApplicationOrgExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_application_org
     *
     * @mbg.generated
     */
    @Select({ "select", "id, chain_id, application_id, org_id, chain_type, org_type, gmt_create, gmt_modified", "from tb_application_org", "where id = #{id,jdbcType=INTEGER}" })
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "chain_id", property = "chainId", jdbcType = JdbcType.INTEGER), @Result(column = "application_id", property = "applicationId", jdbcType = JdbcType.INTEGER), @Result(column = "org_id", property = "orgId", jdbcType = JdbcType.INTEGER), @Result(column = "chain_type", property = "chainType", jdbcType = JdbcType.TINYINT), @Result(column = "org_type", property = "orgType", jdbcType = JdbcType.TINYINT), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP) })
    TbApplicationOrg selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_application_org
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbApplicationOrgSqlProvider.class, method = "updateByExampleSelective")
    int updateByExampleSelective(@Param("record") TbApplicationOrg record, @Param("example") TbApplicationOrgExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_application_org
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbApplicationOrgSqlProvider.class, method = "updateByExample")
    int updateByExample(@Param("record") TbApplicationOrg record, @Param("example") TbApplicationOrgExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_application_org
     *
     * @mbg.generated
     */
    @UpdateProvider(type = TbApplicationOrgSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TbApplicationOrg record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_application_org
     *
     * @mbg.generated
     */
    @Update({ "update tb_application_org", "set chain_id = #{chainId,jdbcType=INTEGER},", "application_id = #{applicationId,jdbcType=INTEGER},", "org_id = #{orgId,jdbcType=INTEGER},", "chain_type = #{chainType,jdbcType=TINYINT},", "org_type = #{orgType,jdbcType=TINYINT},", "gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},", "gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}", "where id = #{id,jdbcType=INTEGER}" })
    int updateByPrimaryKey(TbApplicationOrg record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_application_org
     *
     * @mbg.generated
     */
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @Insert({ "<script>", "insert into tb_application_org (chain_id, ", "application_id, org_id, ", "chain_type, org_type, ", "gmt_create, gmt_modified)", "values<foreach collection=\"list\" item=\"detail\" index=\"index\" separator=\",\">(#{detail.chainId,jdbcType=INTEGER}, ", "#{detail.applicationId,jdbcType=INTEGER}, #{detail.orgId,jdbcType=INTEGER}, ", "#{detail.chainType,jdbcType=TINYINT}, #{detail.orgType,jdbcType=TINYINT}, ", "#{detail.gmtCreate,jdbcType=TIMESTAMP}, #{detail.gmtModified,jdbcType=TIMESTAMP})</foreach></script>" })
    int batchInsert(List<TbApplicationOrg> list);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_application_org
     *
     * @mbg.generated
     */
    @SelectProvider(type = TbApplicationOrgSqlProvider.class, method = "getOneByExample")
    @Results({ @Result(column = "id", property = "id", jdbcType = JdbcType.INTEGER, id = true), @Result(column = "chain_id", property = "chainId", jdbcType = JdbcType.INTEGER), @Result(column = "application_id", property = "applicationId", jdbcType = JdbcType.INTEGER), @Result(column = "org_id", property = "orgId", jdbcType = JdbcType.INTEGER), @Result(column = "chain_type", property = "chainType", jdbcType = JdbcType.TINYINT), @Result(column = "org_type", property = "orgType", jdbcType = JdbcType.TINYINT), @Result(column = "gmt_create", property = "gmtCreate", jdbcType = JdbcType.TIMESTAMP), @Result(column = "gmt_modified", property = "gmtModified", jdbcType = JdbcType.TIMESTAMP) })
    Optional<TbApplicationOrg> getOneByExample(TbApplicationOrgExample example);
}
